package com.study.shengsiyuan.example10;

import java.io.FileInputStream;
import java.net.InetSocketAddress;
import java.nio.channels.FileChannel;
import java.nio.channels.SocketChannel;

public class NewIOClient {
	public static void main(String[] args) throws Exception {
		SocketChannel  socketChannel = SocketChannel.open();
		socketChannel.connect(new InetSocketAddress("127.0.0.1",8899));
		socketChannel.configureBlocking(true);
		String fileName = "F:\\百度网盘\\24248\\1-31\\28_gRPC与Gradle流畅整合及问题解决的完整过程与思考.mkv";

		FileChannel fileChannel =new FileInputStream(fileName).getChannel();
		long startTime =System.currentTimeMillis();
		long transferCount = fileChannel.transferTo(0, fileChannel.size(), socketChannel);
		System.out.println("发送总字节数 ： "+ transferCount +" , 耗时 ： "+(System.currentTimeMillis()-startTime));

		fileChannel.close();
		socketChannel.close();
	}
}
